﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using com.fmtx.IDal;
using com.fmtx.Model;
using fmtx.Framework.DALFactory;

namespace website.Areas.Website.Controllers
{
    public class ArticleController : BaseController
    {
        //
        // GET: /Website/Article/
        IArticle article = DataAccess<IArticle>.GetObject();
        IArticleType articletype = DataAccess<IArticleType>.GetObject();
        IUserInfo user = DataAccess<IUserInfo>.GetObject();
        IPicture picture = DataAccess<IPicture>.GetObject();
        IKeyWord keyword = DataAccess<IKeyWord>.GetObject();

        #region 文章列表
        /// <summary>
        /// 文章列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            List<OutPut> models = ArticleCache.Query(0, 20, null);
            if (models.Count > 0)
            {
                ViewBag.lastid = models.LastOrDefault().Id;
            }
            ViewBag.Keywords = keyword.QueryHost(40,Target.ARTICLE);
            return View(models);
        } 
        #endregion

        #region 文章单体
        /// <summary>
        /// 文章单体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(int id)
        {
            var model = article.Get(id);
            StaticCs.SetShowArticleCount(model.Id);
            ViewBag.user = user.Get(model.Uid);
            ViewBag.newlist = article.QueryNew(5);
            ViewBag.hostlist = article.QueryHost(5);
            ViewBag.praiselist = article.QueryPraise(5);
            ViewBag.ulist = user.QueryArticleCount(12);
            ViewBag.xgarticle = article.Query(5, model.Uid, model.Address);
            ViewBag.piclist = picture.QueryAbout(5, model.Address);
            model.Content = model.Content.FileImgOrUrl();
            return View(model);
        } 
        #endregion

    }
}
